package cn.autowired.exam.controller;

import cn.autowired.exam.base.CommonResponse;
import com.google.common.collect.Maps;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import cn.autowired.exam.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.mapper.EntityWrapper;

import cn.autowired.exam.service.AdminService;

import cn.autowired.exam.entity.Admin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;

/**
 *
 *   @description : Admin 控制器
 *   ---------------------------------
 */
@RestController
@RequestMapping("/admin")
public class AdminController extends AbstractController {
private final Logger logger=LoggerFactory.getLogger(AdminController.class);

    @Autowired
    public AdminService adminService;

    @RequestMapping("/login")
    public ResponseEntity login(String username,String password){
        Admin admin = adminService.selectOne(new EntityWrapper<Admin>()
                .eq(Admin.Field.username, username).eq(Admin.Field.password, password));
        //用户不为空则登录成功
        if (null!=admin){
            HashMap<String, Object> userKey = Maps.newHashMap();
            userKey.put("delayTime",System.currentTimeMillis()+24*60*60*1000);
            userKey.put("creatTime",System.currentTimeMillis());
            return ResponseEntity.ok(userKey);
        } else {
            return ResponseEntity.badRequest().build();
        }
    }

}